import express from 'express';
 
// 创建Express应用
const app = express();
 
// 定义接口路由
interface Route {
  path: string;
  method: string;
  handler: express.Handler;
}
 
// 定义接口路由数组
const routes: Route[] = [
  {
    path: '/hello',
    method: 'get',
    handler: (req, res) => {
      res.send({ message: 'Hello World!' });
    },
  },
];
 
// 注册路由

routes.forEach((route) => {
  if(route.method=='get'||route.method=='GET'){
    app.get(route.path, route.handler);

  }else if(route.method=='post'||route.method=='POST'){
    app.post(route.path, route.handler);

  }

});
 
// 启动服务器
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});